import {observable, action} from 'mobx';
import {ListViewPage} from 'weaver-mobile-page';
import * as API from '../../api/cptApi';


export default class AcceptanceStore {
    @observable selectedTabIndex = 0;
    @observable selectedRowKeys = [];


    @observable showCheck = false;
    @observable InstockList = new ListViewPage.Store({route: '/acceptance/0'});
    @observable InstockListHis = new ListViewPage.Store({route: '/acceptance/1'});


    @action
    init = (path) => {
        switch (path) {
            case "0":
                this.selectedTabIndex = 0;
                break;
            case "1":
                this.selectedTabIndex = 1;
                break;
            default:
                this.selectedTabIndex = 0;
                break;
        }
        this.showCheck=false;
        this.InstockList.clearData();
        this.InstockListHis.clearData();
        this.getInstockList();
        this.getInstockListHis();
    };
    @action
    changeSelectedTabIndex = (num) => {
        this.selectedTabIndex = num;
    }
    @action
    batchDo = () => {
        this.showCheck = true;
        this.InstockList.haveCheck = true;
    };
    @action
    batchApply = (history) => {
        if(this.selectedRowKeys.length===0){
            return;
        }
        this.showCheck = false;
        const IDs = this.selectedRowKeys.join(',');
        history.push('/acceptanceDetail/' + IDs);
        this.selectedRowKeys = [];
    };
    @action
    batchCancel = () => {
        this.showCheck = false;
        this.selectedRowKeys = [];
    };
    @action
    selectKeys = (keys = []) => {
        this.selectedRowKeys = keys;
    };


    @action
    getInstockList = (params) => {//待验收列表
        API.getInstockList().then((res) => {
            const {isright, datas} = res;
            if (isright) {
                this.InstockList.getData({dataKey: datas});
            }
        });
    };

    @action
    getInstockListHis = (params) => {//验收历史列表
        API.getInstockListHis().then((res) => {
            const {isright, datas} = res;
            if (isright) {
                this.InstockListHis.getData({dataKey: datas});
            }
        });
    }


}
